import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PetIslandupdatePetVo } from "./vo/PetIslandupdatePetVo";
import { ResFileConst } from "../../resource/ResFileConst";
import { PetIslandRulePanel } from "./PetIslandRulePanel";
import { PetIslandPowerPanel } from "./PetIslandPowerPanel";
import { PetIslandMemberPanel } from "./PetIslandMemberPanel";
import { PetIslandSituationPanel } from "./PetIslandSituationPanel";
import { PetIslandRecordPanel } from "./PetIslandRecordPanel";
import { SRobIslandGuildInfo } from "../../../../Message/Game/SRobIslandGuildInfo";
import { SRobIslandPlayer } from "../../../../Message/Game/SRobIslandPlayer";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { PetIslandUtil } from "./PetIslandUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { RemainTimeUtil } from "../shopMall/RemainTimeUtil";
import { SRobIslandGuildMemberInfo } from "../../../../Message/Game/SRobIslandGuildMemberInfo";
import { SRobIslandGuildFightingInfo } from "../../../../Message/Game/SRobIslandGuildFightingInfo";
import { SGuildRobIslandLog } from "../../../../Message/Game/SGuildRobIslandLog";
import { Cache } from "../../cache/Cache";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { AIManager } from "../../scene/ai/AIManager";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { FlyFootBmp } from "../mapUI/flyFoot/FlyFootBmp";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { PetComboBoxItemCellRender } from "../pet/changeModel/PetComboBoxItemCellRender";
import { PetItem } from "../pet/PetItem";
import { PetProcessBar } from "../pet/PetProcessBar";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { PetIslandBroadcastItemRenderer } from "./renderer/PetIslandBroadcastItemRenderer";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { AIType } from "../../scene/ai/AIType";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
import { GTileList } from "../../../../com/mui/controls/GTileList";
type int = number;
//class PetIslandPowerBasePanel
    
    export  class PetIslandPowerBasePanel extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(823, 553);
            titleHeight = 26;
            title = Language.getString(28100);
            return;
        }

        /* internal  */onPowerBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandPowerIntrShow));
            return;
        }

        /* internal  */onTextLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._data) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapShowByPosition, this._data.pos));
            }
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            if (this._petListComBo.selectedItem) 
            {
                loc1 = this._petListComBo.selectedItem.value;
            }
            if (loc1 == null) 
            {
                return;
            }
            if (arg1.target.name != "viewBtn") 
            {
                if (arg1.target.name == "unlock" || arg1.target.name == "lock") 
                {
                    loc2 = new PetIslandupdatePetVo();
                    if (this._lockBtn.name != "unlock") 
                    {
                        if (this._lockBtn.name == "lock") 
                        {
                            loc2.uid = loc1.uid;
                            loc2.lock = true;
                        }
                    }
                    else 
                    {
                        loc2.uid = loc1.uid;
                        loc2.lock = false;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandupdatePet, loc2));
                }
            }
            else if (loc1.petId != this._data.petId) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetShowInfo, loc1));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandGetPetInfo, this._data.entityId));
            }
            return;
        }

        /* internal  */onClickHelpBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.addChild(this.rulePanel);
            return;
        }

        /* internal  */onClickPicHelpBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandPicRulePanelShow));
            return;
        }

        /* internal  */set updateByLock(arg1: Boolean)
        {
            if (arg1) 
            {
                this._lockBtn.name = "unlock";
                this._lockBtn.styleName = ResFileConst.PetCpnUnLockBtn;
                this._lockBtn.toolTipData = Language.getString(54664);
            }
            else 
            {
                this._lockBtn.name = "lock";
                this._lockBtn.styleName = ResFileConst.PetCpnLockBtn;
                this._lockBtn.toolTipData = Language.getString(54665);
            }
            return;
        }

        /* internal  */get rulePanel(): PetIslandRulePanel
        {
            if (!this._rulePanel) 
            {
                this._rulePanel = new PetIslandRulePanel(true);
                this._rulePanel.x = this.width + 10;
                this._rulePanel.y = 100;
            }
            return this._rulePanel;
        }

        /* internal  */get powerPanel(): PetIslandPowerPanel
        {
            if (!this._powerPanel) 
            {
                this._powerPanel = new PetIslandPowerPanel();
            }
            return this._powerPanel;
        }

        /* internal  */get memberpanel(): PetIslandMemberPanel
        {
            if (!this._memberpanel) 
            {
                this._memberpanel = new PetIslandMemberPanel();
            }
            return this._memberpanel;
        }

        /* internal  */get situationPanel(): PetIslandSituationPanel
        {
            if (!this._situationPanel) 
            {
                this._situationPanel = new PetIslandSituationPanel();
            }
            return this._situationPanel;
        }

        /* internal  */get recordPanel(): PetIslandRecordPanel
        {
            if (!this._recordPanel) 
            {
                this._recordPanel = new PetIslandRecordPanel();
            }
            return this._recordPanel;
        }

        public petIslandGuildInfoUpdata(arg1: SRobIslandGuildInfo): void
        {
            if (this._powerPanel && this.contains(this._powerPanel) && arg1) 
            {
                this.powerPanel.personalInfoUpata = arg1;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMoveSucceed));
            }
            return;
        }

        public petIslandGuildPersonalInfoUpata(arg1: SRobIslandPlayer): void
        {
            this._data = arg1;
            var loc1=HTMLUtil.addColor("  (+" + PetIslandUtil.getAdditionByPos(this._data.guildPos) + "%)", GlobalStyle.color5);
            this._petName.text = arg1.petName;
            this._petItem.petPic = arg1.petChangeCode;
            this._lifeBar.setValue(arg1.life, arg1.maxLife);
            this._posName.htmlText = Language.getStringByParam(28124, GameDefConfig.instance.getPetIslandGuildPosName(arg1.guildPos) + loc1);
            this._pos.htmlText = Language.getStringByParam(28123, PetIslandUtil.getPosition(arg1, true));
            this._enterTime.htmlText = Language.getStringByParam(28121, RemainTimeUtil.getRemainMinute(arg1.joinSeconds, true, true, true, false, true));
            PetIslandUtil.setSelectPet(this._petListComBo, arg1.petId);
            this.updateByLock = this._data.lockPet;
            if (arg1.moveCD > 0) 
            {
                this._moveCoolTime.text = RemainTimeUtil.getRemainMinute(arg1.moveCD, true, true, true, false, true);
            }
            else 
            {
                this._moveCoolTime.text = "0" + Language.getString(35609);
            }
            return;
        }

        public petIslandGuildMemberInfoUpata(arg1: SRobIslandGuildMemberInfo): void
        {
            if (this._memberpanel && this.contains(this._memberpanel)) 
            {
                this.memberpanel.data = arg1.players;
            }
            return;
        }

        public petIslandGuildFightingInfoUpata(arg1: SRobIslandGuildFightingInfo): void
        {
            if (this._situationPanel && this.contains(this._situationPanel)) 
            {
                this.situationPanel.data = arg1;
            }
            return;
        }

        public petIslandGuildLogUpdata(arg1: SGuildRobIslandLog): void
        {
            if (this._recordPanel && this.contains(this._recordPanel)) 
            {
                this.recordPanel.data = arg1.logs;
            }
            return;
        }

        public onMoneyUpdate(): void
        {
            var loc1=Cache.instance.role.money.robIslandCoin;
            this._petCoinTxt.text = Language.getStringByParam(28246, loc1);
            return;
        }

        public showPanelByIndex(arg1: int): void
        {
            this._tabBar.selectedIndex = arg1;
            this._tabBar.dispatchEvent(new MuiEvent(MuiEvent.GTABBAR_SELECTED_CHANGE, arg1));
            return;
        }

        public setPetListComBo(): void
        {
            var loc1=this._petListComBo.selectedIndex;
            this._petListComBo.dataProvider = PetIslandUtil.petComboDp;
            if (this._petListComBo.dataProvider.length > 0) 
            {
                this._petListComBo.selectedIndex = loc1;
            }
            else 
            {
                this._petListComBo.selectedIndex = -1;
            }
            return;
        }

        /* internal  */onResCompl(): void
        {
            ObjCreate.createGBitmap(ImagesConst.PetIslandPowerBaseInfoText, 85, 45, this);
            ObjCreate.createGBitmap(ImagesConst.PetIslandPowerBaseCoolDownTxt, 50, 290, this);
            return;
        }

        /* internal  */onExchangeLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._npcTarget) 
            {
                this.hide();
                AIManager.onAutoPathAIControl(this._npcTarget);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.onMoneyUpdate();
            this.setPetListComBo();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._petListComBo.selectedIndex = -1;
            if (this._rulePanel) 
            {
                DisplayUtil.removeMe(this._rulePanel);
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 38, 225, 503, this);
            ObjCreate.createBg(245, 67, 560, 474, this);
            ObjCreate.createBg(30, 153, 200, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(30, 212, 200, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(30, 311, 200, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(17, 35, 230, 35, this, ImagesConst.RbListHeader);
            ObjCreate.createBg(17, 350, 230, 35, this, ImagesConst.RbListHeader);
            this._tabBar = new GTabBar();
            this._tabBar.horizontalGap = 2;
            this._tabBar.buttonWidth = 70;
            this._tabBar.buttonFilters = [FilterConst.glowFilter];
            this._tabBar.selectedIndex = 0;
            this._tabBar.dataProvider = Language.getArray(28110);
            this._tabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onTabBarSelectedChange);
            ObjCreate.setObjAttri(this._tabBar, 267, 45, -1, -1, this);
            this._petCoinTxt = ObjCreate.createGTextField("", 495, 48, 120, 20, this, GlobalStyle._textFormat2);
            this._npcTarget = Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectRobIslandExchange);
            var loc1=new FlyFootBmp();
            ObjCreate.setObjAttri(loc1, 673, 48, -1, -1, this);
            loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            var loc2=ObjCreate.createTextField(Language.getString(28247), 620, 48, 55, 20, this, GlobalStyle.textFormatWhite, true);
            loc2.addEventListener(flash.events.TextEvent.LINK, this.onExchangeLinkHandler);
            var loc3=ObjCreate.createImgBtn(ImagesConst.RuleExplain, 745, 42, 60, 23, this, "Button");
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHelpBtnHandler);
            var loc4;
            (loc4 = ObjCreate.createGButton(Language.getString(28250), 702, 42, 40, 23, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onClickPicHelpBtnHandler);
            var loc5=new GTextFormat(FontUtil.stXingkaiName, 20, GlobalStyle.color9Uint);
            this._petListComBo = ObjCreate.createGComboBox(65, 160, 130, 25, null, this);
            this._petListComBo.selectedIndex = -1;
            this._petListComBo.prompt = Language.getString(28103);
            this._petListComBo.dropdown.setStyle("cellRenderer", PetComboBoxItemCellRender);
            this._petListComBo.addEventListener(flash.events.Event.CHANGE, this.onPetComboxChangeHandler);
            ObjCreate.createGImageBitmap(ImagesConst.PetIslandAvatarBg, 25, 75, this);
            this._petItem = new PetItem();
            this._petItem.isDragAble = false;
            this._petItem.isDropAble = false;
            ObjCreate.setObjAttri(this._petItem, 36, 87, 51, 51, this);
            this._viewBtn = ObjCreate.createGButton("", 40, 180, 59, 32, this, "PetCpnViewButton");
            this._viewBtn.name = "viewBtn";
            this._viewBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._lockBtn = ObjCreate.createGLoadedButton(ResFileConst.PetCpnLockBtn, 155, 180, 59, 32, this);
            this._lockBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._petName = ObjCreate.createGTextField("", 100, 95, 125, 20, this, GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat1, flash.text.TextFormatAlign.CENTER));
            this._petName.mouseEnabled = false;
            this._lifeBar = new PetProcessBar(ImagesConst.RedBar10, 125);
            this._lifeBar.move(100, 125);
            this._lifeBar.setValue(0, 0);
            this.addChild(this._lifeBar);
            this._posName = ObjCreate.createGTextField(Language.getStringByParam(28111, ""), 50, 217, 150, 20, this);
            this._posName.mouseEnabled = false;
            this._enterTime = ObjCreate.createGTextField(Language.getStringByParam(28112, ""), 50, 240, 150, 20, this);
            this._enterTime.mouseEnabled = false;
            this._pos = ObjCreate.createGTextField(Language.getStringByParam(28113, ""), 50, 263, 150, 20, this);
            this._pos.addEventListener(flash.events.TextEvent.LINK, this.onTextLinkHandler);
            this._moveCoolTime = ObjCreate.createGTextField("", 143, 290, 150, 20, this, GlobalStyle._textFormat9);
            this._moveCoolTime.mouseEnabled = false;
            this._enterBtn = ObjCreate.createGButton(Language.getString(28118), 45, 320, 72, 28, this, "ButtonRed");
            this._enterBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onEnterBtnHandler);
            this._powerBtn = ObjCreate.createGButton(Language.getString(28119), 145, 320, 72, 28, this, "ButtonRed");
            this._powerBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onPowerBtnHandler);
            this._miniMapBg = ObjCreate.createGImageBitmap(ImagesConst.PetIslandMiniMapBg, 25, 382, this);
            this._list = ObjCreate.createTileList(28, 382, 200, 140, this);
            this._list.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._list.columnWidth = 200;
            this._list.rowHeight = 58;
            this._list.setStyle("cellRenderer", PetIslandBroadcastItemRenderer);
            LoaderHelp.addResCallBack(ResFileConst.PetIslandPowerBase, this.onResCompl);
            return;
        }

        /* internal  */onTabBarSelectedChange(arg1: MuiEvent): void
        {
            var loc1=null;
            DisplayUtil.removeMe(this._curPanel);
            var loc2=this._tabBar.selectedIndex;
            switch (loc2) 
            {
                case 0:
                {
                    this._curPanel = this.powerPanel;
                    break;
                }
                case 1:
                {
                    this._curPanel = this.memberpanel;
                    break;
                }
                case 2:
                {
                    this._curPanel = this.recordPanel;
                    break;
                }
            }
            this._curPanel.x = 245;
            this._curPanel.y = 49;
            this.addChild(this._curPanel);
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandPowerBaseDataReq, this._tabBar.selectedIndex));
            return;
        }

        /* internal  */onPetComboxChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            if (this._data) 
            {
                loc1 = this._petListComBo.dataProvider.getItemAt(this._petListComBo.selectedIndex).value as SPetInfo;
                if (loc1) 
                {
                    if (loc1.petId != this._data.petId) 
                    {
                        this.updateByLock = false;
                    }
                    else 
                    {
                        this.updateByLock = this._data.lockPet;
                    }
                }
            }
            return;
        }

        public broadcastUpdata(arg1: Array<any>): void
        {
            this._list.dataProvider = new DataProvider(arg1);
            this._list.drawNow();
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._npcTarget) 
            {
                this.hide();
                AIManager.onAIControl(this._npcTarget, AIType.AI_Convey);
            }
            return;
        }

        /* internal  */onEnterBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapShow));
            return;
        }

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_curPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_powerPanel: PetIslandPowerPanel;

        /* internal */ /* var */_memberpanel: PetIslandMemberPanel;

        /* internal */ /* var */_situationPanel: PetIslandSituationPanel;

        /* internal */ /* var */_rulePanel: PetIslandRulePanel;

        /* internal */ /* var */_petListComBo: GComboBox;

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_viewBtn: GButton;

        /* internal */ /* var */_lockBtn: GLoadedButton;

        /* internal */ /* var */_petName: GTextFiled;

        /* internal */ /* var */_lifeBar: PetProcessBar;

        /* internal */ /* var */_posName: GTextFiled;

        /* internal */ /* var */_enterTime: GTextFiled;

        /* internal */ /* var */_pos: GTextFiled;

        /* internal */ /* var */_moveCoolTime: GTextFiled;

        /* internal */ /* var */_enterBtn: GButton;

        /* internal */ /* var */_powerBtn: GButton;

        /* internal */ /* var */_miniMapBg: GImageBitmap;

        /* internal */ /* var */_npcTarget: TaskTargetInfo;

        /* internal */ /* var */_petCoinTxt: GTextFiled;

        /* internal */ /* var */_data: SRobIslandPlayer;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_recordPanel: PetIslandRecordPanel;
    }
